<?php
include "../include/config.php";
include "../include/db.php";


$query = "SELECT id_menu, descripcion FROM admin_menu WHERE id_menu_padre = 0 AND habilitado = 'S' ORDER BY orden ASC"; //menues principales
$result = mysql_query($query) or trigger_error(mysql_error());

$query3 = "SELECT id_menu, descripcion FROM admin_menu WHERE id_menu_padre <> 0 AND habilitado = 'S' ORDER BY orden ASC"; 
$result3 = mysql_query($query3) or trigger_error(mysql_error());


/* cant de submenues x menu */
$query4 = "SELECT id_menu, COUNT(*) cant
		FROM admin_menu
		WHERE id_menu_padre <> 0 AND habilitado = 'S' 
		GROUP BY id_menu_padre"; 
$result4 = mysql_query($query4) or trigger_error(mysql_error());

$menues = array();
while ($row4 = mysql_fetch_array($result4)) {
    $nro = $row4['id_menu'];
    $menues[$nro] = $row4['cant'];
	//print_r()
}

//print_r($menues); die();
/**/


$query2 = "SELECT id_usuario, nombre_usuario FROM admin_usuarios WHERE c_estado = 1"; //usuarios
$result2 = mysql_query($query2) or trigger_error(mysql_error());

$CANT_COLUMNAS = mysql_num_rows($result); //menues
$CANT_SUBMENUES = mysql_num_rows($result3);

// echo "<pre>";
// print_r($DEPARTAMENTOS);
// echo "</pre>";
// echo $CANT_FILAS;
// die();

$fila = 1;
$pos = 0;
$next = 0;

?>

<div id="">holass</div>    

<table align="center" border="1" cellpadding="1" cellspacing="1" style="width: 827px; ">
		
	<thead>
		<tr>
			<th></th>
			<?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
					$id = $row['id_menu']; 
			?>
				<th colspan="<?php echo $menues[$id] ?>" rowspan="1">	<?php echo $row['descripcion'] ?></th>
			<?php  } ?>
		</tr>
	</thead>
	<tbody>		
		<tr>
			<td></td>
			<?php while ($row3 = mysql_fetch_array($result3, MYSQL_ASSOC)) {  ?>
				<td>	<?php echo $row3['descripcion'] ?>	</td>
			<?php  } ?>
		</tr>
		<?php while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?>
		<tr>
				<td><?php echo $row2['nombre_usuario'] ?></td>
			<?php for ($i=0; $i<$CANT_SUBMENUES; $i++) { ?>
				<td>	<?php echo "as" ?>	</td>
			<?php  } ?>
		</tr>
		<?php  } ?>
	</tbody>
</table>

<script>

(function(){
	var unaVariableGlobal = "holassssssssss";


	$(document).ready(function(){    
	   //alert("asd: " + unaVariableGlobal)
	});

	
})();

</script>